﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using GeekShop.Properties;
using System.Drawing.Drawing2D;

namespace GeekShop.Commands.Fill
{
    public class Color : ICommand
    {
        #region Fields
        private Picture picture;
        private Bitmap oldBitmap;
        private System.Drawing.Color color;
        #endregion

        #region Contrustor
        public Color(Picture picture, System.Drawing.Color color)
        {
            this.picture = picture;
            this.color = color;
        }
        #endregion

        #region ICommand Members
        public void Do()
        {
            Bitmap bitmap = this.picture.SelectedLayer.Bitmap;
            this.oldBitmap = (Bitmap)bitmap.Clone();
            Graphics g = Graphics.FromImage(bitmap);
            Region region = (Region)this.picture.Mask.Region.Clone();
            region.Translate(
                -this.picture.SelectedLayer.Location.X,
                -this.picture.SelectedLayer.Location.Y
            );
            g.FillRegion(new SolidBrush(this.color), region);
        }
        public void Undo()
        {
            this.picture.SelectedLayer.Bitmap = (Bitmap)this.oldBitmap.Clone();
        }
        #endregion
    }
}
